package com.pctx.bibaregisterlogin.controller;

import com.github.pagehelper.PageHelper;
import com.pctx.bibacommon.result.Result;
import com.pctx.bibaregisterlogin.pageHelper.PageInfo;
import com.pctx.bibaregisterlogin.pojo.MessageOrder;
import com.pctx.bibaregisterlogin.service.MessageOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by chason on 2018/3/9.18:51
 */
@RestController
@RequestMapping("message")
public class MessageController {
    @Autowired
    private MessageOrderService messageOrderService;

    @GetMapping("page")
    public Result orderPage(@RequestParam(value = "companyUuid", required = true) String companyUuid
            , @RequestParam(value = "page", defaultValue = "1") Integer page
            , @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) throws Exception {
        PageHelper.startPage(page, pageSize);
        List<MessageOrder> list = messageOrderService.getByCompanyUuid(companyUuid);
        return Result.success(new PageInfo(list));
    }

    @GetMapping("read")
    public Result readMessage(@RequestParam(value = "uuid", required = true) String uuid) throws Exception {
        boolean flag = messageOrderService.readMessage(uuid);
        if (flag)
            return Result.success("操作成功");
        else
            return Result.error("操作失败");
    }
}
